﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Interpreter
{
	internal class FileInfo
	{
		public string Name { get; private set; }
		public string[] Lines { get; private set; }

		public FileInfo(string name, string contents)
		{
			this.Name = name;
			this.Lines = contents.Split('\n');
		}

		/// <param name="rawFileInfo">Without the size prefix</param>
		public static FileInfo ParseFromRawData(string rawFileInfo)
		{
			char c;
			for (int i = 0; i < rawFileInfo.Length; ++i)
			{
				c = rawFileInfo[i];
				if (c == '|')
				{
					string filename = rawFileInfo.Substring(0, i);
					string contents = rawFileInfo.Substring(i + 1);
					return new FileInfo(filename, contents);
				}
			}

			throw new Exception("Corrupted source code info.");
		}
	}
}
